package demo1.NiceDemo.picture;

import javax.swing.*;
import java.awt.*;
import java.io.File;

public class PictureTest extends JFrame {
    public PictureTest(String title) {
        super(title);
        PictureView picture = new PictureView();
        this.setContentPane(picture);
        //设置背景色
        picture.setBackgroundColor(Color.WHITE);
        //设置要显示的图片
        picture.setImage(new File("data/picture/pragmatism.jpg"));
        //picture.setImage("/res/Carefree Melody.png");
    }
}





//重复的操作，已被封装进PictureView
//    public void pictureView() {
//        PictureView picture = new PictureView();
//        this.setContentPane(picture);
//        //设置背景色
//        picture.setBackgroundColor(Color.BLUE);
//        //设置要显示的图片
//        try {
//            Image image = ImageIO.read(new File("data/picture/pragmatism.jpg"));
//            picture.setImage(image);
//        }catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    public  void getResource() {
//        PictureView picture = new PictureView();
//        this.setContentPane(picture);
//        //设置背景色
//        picture.setBackgroundColor(Color.RED);
//        try {
//            InputStream res = this.getClass().getResourceAsStream("/res/Carefree Melody.png");
//            Image image = ImageIO.read(res);
//            picture.setImage(image);
//        }catch (IOException e) {
//            e.printStackTrace();
//        }
//    }

